/*****************************************************
Date: 10/1/2024
This file replicates all the reduced-form results.
******************************************************/


cap log close
log using replication_reduced_form.log, replace

*** Table 1 ***

use "mayor_data.dta", replace

sum gdp_pc_01_04 lindustry_index pfunds fr_stolen d_fr_stolen pop2001 pop_d1 pop_d2 pop_d3 PesResAlfaRate d_2nd_term d_run reeleito00_04 reeleito00_04_b college pref_idade cand_wealth08  if d_2nd_term~=.

*** Table 2 ***

reg fr_stolen d_2nd_term  pref_edu mayor_age lnfunds lpop2000 pib_pc2001   , rob

* Public Consumption Statistics
reg lngdp_pc_01_04 lnfunds ln_fr_stolen d_2nd_term ln_pop_01_04 PesResAlfaRate* pib2001*, rob
 
* Running for Reelection Statistics
reg d_run audit d_fr_stolen_audit lngdp_pc_01_04 lngdp_pc_priv_01_04 mayor_age ln_pop2001 PesResAlfaRate, rob

* Electoral Outcome Statistics
reg reeleito00_04_b audit d_fr_stolen_audit lngdp_pc_01_04 lngdp_pc_priv_01_04 mayor_age relcon2 ln_pop2001 PesResAlfaRate, rob


use "wage_data.dta"

reg wage_mean_past_norm  pref_edu mayor_age mayor_age2 pop2000 audit d_fr_stolen_audit, rob


*** Table 5 ***

use "wage_model.dta"
bootstrap, reps(1000) seed(13232) saving(wage_bs, replace): reg wage pref_edu age age2 pop_d2 pop_d3, rob


*** Table 9 ***
use "public_goods.dta", clear

global controls "IDHM T_AGUA T_LIXO T_LUZ nschools shesc_comp  nclinics "

corr pib_pc $controls
corrtex pib_pc $controls, file(temp) replace sig dig(2) land


*** Table 10 ***
use "candidate_pool.dta", replace

gen eligible = pop2000<=450000
gen post = ano_eleicao>2003
gen treatment = eligible*post

local varlist "ncandidates sh_male sh_college age" 

foreach X of local varlist {
	areg `X' treatment i.ano_eleicao if ncandidates<=8&ano_eleicao~=2016, abs(sigla_ue) cluster(sigla_ue)
}


*** Table 11 ***
use "cra.dta", replace
gen post = ano_eleicao>=2016
gen ano_eleicao_2 = ano_eleicao^2

replace wealth = wealth/10000

local varlist "ncandidates sh_male sh_college age wealth" 
foreach X of local varlist {
	areg `X' post ano_eleicao if pop2000<=450000, abs(cod_ibge6) cluster(cod_ibge6)	
	areg `X' post ano_eleicao ano_eleicao_2  if pop2000<=450000, abs(cod_ibge6) cluster(cod_ibge6)	
}

log close
exit

